package com.thinkgem.jeesite.modules.gen.util;

import com.alibaba.fastjson.serializer.PropertyPreFilter;
import com.alibaba.fastjson.serializer.SerializerFeature;

/**
 * @author xhl
 * @Title: JsonUtil
 * @Package com.banksoft.common.util
 * @Description:
 * @date 2018-10-13 11:11
 */
public class JsonUtil {

    /**
     * fastjson转json
     *
     * @param object
     * @return
     */
    public static Object toJSON(Object object) {
        return com.alibaba.fastjson.JSON.toJSON(object);
    }

    /**
     * fastjson转jsonString
     *
     * @param object
     * @return
     */
    public static String toJSONString(Object object) {
        return com.alibaba.fastjson.JSON.toJSONString(object, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty);
    }

    /**
     * fastjson转jsonString，并过滤掉指定字段
     *
     * @param object
     * @param filter
     * @return
     */
    public static String toJSONString(Object object, PropertyPreFilter filter) {
        return com.alibaba.fastjson.JSON.toJSONString(object, filter, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty);
    }
}
